<template>
  <div>
    <el-card class="box-card">
      <div slot="header" class="clearfix">
        <span style="line-height: 36px;">财务审批</span>
      </div>
      <s-table
        :table="table"
        @http="tableWatch">
        <el-row>
          <el-col :xs="24" :lg="{span: 12, offset: 0}" class="">
            <el-form-item label="审核状态" prop="examine">
              <el-select v-model="autoVue_table_examine" placeholder="结算类别">
                <el-option
                  label="全部"
                  value="">
                </el-option>
                <el-option
                  label="待审核"
                  :value="0">
                </el-option>
                <el-option
                  label="已审核"
                  :value="1">
                </el-option>
                <el-option
                  label="不通过"
                  :value="2">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
          <el-col :xs="24" :lg="{span: 12, offset: 0}">
            <el-form-item label="报销类型" prop="type">
              <el-select v-model="autoVue_table_type" placeholder="报销类型">
                <el-option
                  label="全部"
                  value="">
                </el-option>
                <el-option
                  label="成本费用"
                  value="expenseCost">
                </el-option>
                <el-option
                  label="暂借款"
                  value="borrowing">
                </el-option>
                <el-option
                  label="差旅"
                  value="travelExpense">
                </el-option>
                <el-option
                  label="奖励扣款"
                  value="rewardDeduction">
                </el-option>
                <el-option
                  label="结算单"
                  value="adviceSettlement">
                </el-option>
              </el-select>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :lg="{span: 12, offset: 0}">
            <el-form-item label="报销单号" prop="number">
              <el-input type="text"
                        class="input"
                        v-model="autoVue_table_number"
                        placeholder="报销单号"></el-input>
            </el-form-item>
          </el-col>
        <el-col :xs="24" :lg="{span: 12, offset: 0}">
          <el-form-item label="结算类别" prop="settleCategory">
            <el-select v-model="autoVue_table_settleCategory" placeholder="结算类别">
              <el-option
                label="全部"
                value="">
              </el-option>
              <el-option
                label="费用"
                :value="2">
              </el-option>
              <el-option
                label="成本"
                :value="1">
              </el-option>
            </el-select>
          </el-form-item>
        </el-col>
        </el-row>
        <el-row>
        <el-col :xs="24" :lg="{span: 12, offset: 0}">
          <el-form-item label="报销人员" prop="reimbursementName">
            <el-input type="text"
                      class="input"
                      v-model="autoVue_table_reimbursementName"
                      placeholder="报销人员"></el-input>
          </el-form-item>
        </el-col>
          <el-col :xs="24" :lg="{span: 12, offset: 0}">
            <el-form-item label="收款方" prop="supplierName">
              <el-input type="text"
                        class="input"
                        v-model="autoVue_table_supplierName"
                        placeholder="收款方"></el-input>
            </el-form-item>
          </el-col>
        </el-row>
        <el-row>
          <el-col :xs="24" :lg="{span: 23, offset: 0}" class="">
            <el-form-item label="归属期间" prop="period">
              <el-date-picker
                v-model="autoVue_table_period"
                type="daterange"
                range-separator="至"
                start-placeholder="开始日期"
                end-placeholder="结束日期">
              </el-date-picker>
            </el-form-item>
          </el-col>
        </el-row>

        <el-form-item label="结算审核" slot="multiSelect" prop="multiSelect">
          <el-row>
            <el-col>
              <el-button size="small"
                         type="primary"
                         @click="audit(1)">通过</el-button>
              <el-button size="small"
                         type="primary"
                         @click="audit(2)">不通过</el-button>
            </el-col>
          </el-row>
        </el-form-item>
      </s-table>
    </el-card>
  </div>
</template>
<script>
  import {AutoVue, SplitK} from '~/plugins/Tools';

  function __cards () {
    return [
      {
        title: '成本费用报销单',
        code: 'expenseCost',
        body: 'test',
        img: 'apple',
      },
      {
        title: '差旅费用报销单',
        code: 'travelExpense',
        body: 'test',
        img: 'apple',
      },
      {
        title: '暂借款借支单',
        code: 'borrowing',
        body: 'test',
        img: 'apple',
      },
      {
        title: '结算单',
        code: 'adviceSettlement',
        body: 'test',
        img: 'apple',
      },
      {
        title: '奖励扣款报销单',
        code: 'rewardDeduction',
        body: 'test',
        img: 'apple',
      },
    ];
  }

  export default AutoVue({
    data: {
      table: {
        column: [
          {'label': '报销类型', 'prop': 'show_type', 'minWidth': '0px', search: true},
          {'label': '报销单号', 'prop': 'number', 'minWidth': '200px', search: true},
          {'label': '报销人员', 'prop': 'reimbursementName', 'minWidth': '0px', search: true},
          {'label': '所属部门', 'prop': 'departmentName', 'minWidth': '300px', search: true},
          {'label': '费用所属', 'prop': 'bearDepartmentName', 'minWidth': '300px', search: true},
          {'label': '结算类别', 'prop': 'show_settleCategory', 'minWidth': '0px', search: true},
          {'label': '收款方', 'prop': 'show_supplierId', 'minWidth': '300px', search: true, searchName: 'supplierName'},
          {'label': '费用项目', 'prop': 'costItem', 'minWidth': '300px', search: true},
          {'label': '所属期间',
            'prop': 'period',
            formatter: (row, column) => {
              return this.a.methods.formatterTime(row[column.property || column], 22);
            },
            type: 'DateRange',
            search: true,
            'minWidth': '120px'},
          {'label': '预计结算时间', 'prop': 'estimatedSettleTime', 'minWidth': '120px', type: 'DateRange', search: true},
          {'label': '报销金额',
            'prop': 'settleAmout',
            'minWidth': '100px',
            search: true,
            formatter: (row, column) => {
              return SplitK(row[column.property || column]);
            }},
          {'label': '扣款金额',
            'prop': 'debitAmout',
            'minWidth': '100px',
            search: true,
            formatter: (row, column) => {
              return SplitK(row[column.property || column]);
            }},
          {'label': '奖励金额',
            'prop': 'rewardAmout',
            'minWidth': '100px',
            search: true,
            formatter: (row, column) => {
              return SplitK(row[column.property || column]);
            }},
          {'label': '应结算',
            'prop': 'actualSettleAmout',
            'minWidth': '100px',
            search: true,
            formatter: (row, column) => {
              return SplitK(row[column.property || column]);
            }},
          {'label': '油卡金额',
            'prop': 'oilcardSettleAmout',
            search: true,
            'minWidth': '100px',
            formatter: (row, column) => {
              return SplitK(row[column.property || column]);
            }},
          {'label': '现金金额',
            'prop': 'cashAmout',
            search: true,
            'minWidth': '100px',
            formatter: (row, column) => {
              return SplitK(row[column.property || column]);
            }},
          { label: '审核状态',
            prop: 'examine',
            elTag: {
              filterType (type) {
                switch (type) {
                case 0:
                  return 'primary';
                case 1:
                  return 'success';
                case 2:
                  return 'danger';
                }
              },
            },
            formatter: (row, column) => {
              let step = parseInt(row[column.property || column]);
              switch (step) {
              case 0:
                return '待审核';
              case 1:
                return '已审核';
              case 2:
                return '不通过';
              }
            },
            minWidth: '0px',
            search: true,
          },
        ],
        key: 'id',
        url: '/settlement/searchByPageForFinance',
        muti: true,
        multiSelect: true,
      },
      cards: __cards(),
    },
    methods: {
      async audit (type) {
        let multipleSelection = this.table.multipleSelection;
        if (multipleSelection.length < 1) {
          return this.$alert('您还未选择任何数据！', '提示');
        } else {
          let ids = [];
          let bool = true;
          multipleSelection.forEach(item => {
            ids.push(item.id);
            if (item.examine === 1) {
              bool = false;
              return this.$alert('您选中的数据含有已审核的数据！，请重新选择', '提示');
            }
          });
          if (bool) {
            await this.post('/settlement/toExamina/' + type, ids);
            this.tableWatch('table');
          }
        }
      },
    },
    mounted: function () {
      this.tableWatch('table');
    },
  });
</script>

<style scoped lang="scss">
  .card {
    float: left;
    border-radius: 3px;
    box-shadow: 0 2px 10px 1px rgba(0, 0, 0, .1);
    height: 110px;
    width: 800px;
    margin: 15px;
    padding: 25px;
    position: relative;
    vertical-align: top;
    transition: .4s;
    cursor: pointer;
    &:hover {
      box-shadow: 0 10px 20px 1px rgba(0, 0, 0, .1);
      text-decoration: none;
    }
  }

  .card__icon {
    font-size: 24px;
    left: 28px;
    position: absolute;
    top: 25px;
    color: #20a0ff;
  }

  .card__title {
    color: #20a0ff;
    margin-top: 0;
    margin-bottom: 10px;
    margin-left: 40px;
  }

  .card__body {
    line-height: 22px;
    margin-left: 40px;
  }

  @media screen and (max-width: 800px) {
    .card {
      width: calc(100% - 80px);
    }
  }

  .__table .el-card {
    margin: 0;
  }
</style>
